home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PROT100.ZIP / XCRC.ASM < prev    next >
Assembly Source File  |  1990-05-12  |  2KB  |  97 lines

  1. title    'XCRC linkage to CRC'
  2. name    xcrc
  3. cseg    segment byte public 'CODE'
  4.     assume    cs : cseg
  5.     public    crcasm, crca
  6. ;
  7. ; PROCEDURE crc(byte, VAR integer);
  8. ; incorporates byte in integer using x^16+x^12+x^5+1
  9. crcasm    proc    far
  10.     pop    dx;        return offset
  11.     pop    cx;        return segment
  12.     pop    bx;        ^integer, offset
  13.     pop    es;        ^integer, segment
  14.     pop    ax;        al := byte
  15.     push    cx;        return segment
  16.     push    dx;        return offset
  17.     mov    dx,es:[bx];    old crc value
  18. ;    ------        busy regs - speed optimized.
  19.     xor    al,dh;    al ah dl dh
  20.     mov    ah,al;     x  x  x  
  21.     ror    al,1;     x  x  x
  22.     ror    al,1;     x  x  x
  23.     ror    al,1;     x  x  x
  24.     ror    al,1;     x  x  x
  25.     and    al,0fh;     x  x  x
  26.     xor    al,ah;   x     x
  27.     mov    dh,al;     x     x  .  
  28.     ror    al,1;     x     x  .
  29.     ror    al,1;     x     x  .
  30.     ror    al,1;     x     x  .
  31.     mov    ah,al;     x  x  x  .
  32.     and    al,1fh;     x  x  x  .
  33.     xor    al,dl;     x  x     .
  34.     xchg    dh,al;     .  .     .
  35.     mov    dl,al;        .  .  .
  36.     mov    al,ah;     x  x  .  x
  37.     and    al,0e0h; x  x     x
  38.     xor    dl,al;        .  .  .
  39.     ror    ah,1;        x  x  x
  40.     and    ah,0f0h;    x  x  x
  41.     xor    dh,ah;           x  x    one byte done
  42. ;    -----
  43.     mov    es:[bx],dx;    save result
  44.     ret
  45. crcasm    endp
  46. ;
  47. ; PROCEDURE crca(VAR byte array; VAR integer);
  48. ; incorporates bytes in integer using x^16+x^12+x^5+1
  49. crca    proc    far
  50.     pop    dx;        return offset
  51.     pop    ax;        return segment
  52.     pop    bx;        ^integer, offset
  53.     pop    es;        ^integer, segment
  54.     pop    cx;        length
  55.     pop    si;        ^array, offset
  56.     pop    di;        ^array, segment
  57.     push    ax;        return segment
  58.     push    dx;        return offset
  59.     push    ds;        save
  60.     mov    ds,di;        array segment
  61.     mov    dx,es:[bx];    incoming crc
  62.     jcxz    crca2;        zero length
  63. crca1:    lodsb
  64. ;    ------        busy regs - speed optimized
  65.     xor    al,dh;    al ah dl dh
  66.     mov    ah,al;     x  x  x  
  67.     ror    al,1;     x  x  x
  68.     ror    al,1;     x  x  x
  69.     ror    al,1;     x  x  x
  70.     ror    al,1;     x  x  x
  71.     and    al,0fh;     x  x  x
  72.     xor    al,ah;   x     x
  73.     mov    dh,al;     x     x  .  
  74.     ror    al,1;     x     x  .
  75.     ror    al,1;     x     x  .
  76.     ror    al,1;     x     x  .
  77.     mov    ah,al;     x  x  x  .
  78.     and    al,1fh;     x  x  x  .
  79.     xor    al,dl;     x  x     .
  80.     xchg    dh,al;     .  .     .
  81.     mov    dl,al;        .  .  .
  82.     mov    al,ah;     x  x  .  x
  83.     and    al,0e0h; x  x     x
  84.     xor    dl,al;        .  .  .
  85.     ror    ah,1;        x  x  x
  86.     and    ah,0f0h;    x  x  x
  87.     xor    dh,ah;           x  x    one byte done
  88. ;    -----
  89.     loop    crca1;        over the array
  90.     mov    es:[bx],dx;    save result
  91. crca2:    pop    ds
  92.     ret
  93. crca    endp
  94.  
  95. cseg    ends
  96.     end
  97.